﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/*
 给定一个包含学生的列表，每个学生有姓名和年龄。筛选出年龄大于 20 岁的学生，并只选择他们的姓名。
 */
namespace CS_BEGINNER_TO_PROFICIENT.STD.LinqSTD
{
    public class P2
    {
        public static void Execute()
        {
            List<Student> students = new List<Student>
            {
                new Student { Name = "c", Age = 29 },
                new Student { Name = "d", Age = 19 },
                new Student { Name = "a", Age = 20 }
            };

            var res = from student in students where student.Age >= 20 select student.Name;
            foreach (var i in res)
            {
                Console.WriteLine(i);
            }

            // 方法语法
            var result = students.Where(s => s.Age >= 20).Select(s => s.Name);
            foreach (var i in result)
            {
                Console.WriteLine(i);
            }
        }
    }

    public class Student
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
